// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })

// 获取不到文件夹中全部的图片在线地址

// cloud://cloud1-7g5ffdpz146dadd4.636c-cloud1-7g5ffdpz146dadd4-1319236987/applicantCertificate/1693145004850_oM7WQ6956w1rtZi0_fcGNnmCJDmw.png

// https://636c-cloud1-7g5ffdpz146dadd4-1319236987.tcb.qcloud.la/applicantCertificate/1693145004850_oM7WQ6956w1rtZi0_fcGNnmCJDmw.png
  // => https://636c-cloud1-7g5ffdpz146dadd4-1319236987.tcb.qcloud.la/applicantCertificate/ + 图片名


exports.main = async (event, context) => {
  try {
    const fileList = ['cloud://cloud1-7g5ffdpz146dadd4.636c-cloud1-7g5ffdpz146dadd4-1319236987/applicantCertificate/1693145004850_oM7WQ6956w1rtZi0_fcGNnmCJDmw.png']
    const result = await cloud.getTempFileURL({ fileList })

    return {
      code: 0,
      data: result.fileList[0].tempFileURL
    }
  } catch (err) {
    return {
      code: -1,
      message: '获取永久链接失败'
    }
  }
}